﻿using AutoMapper;
using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Cultures;
using MediatR;
using System.IO.Pipelines;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Cultures
{
    public class QueryCultureHandler : IRequestHandler<QueryCultureCommand, ApiResult<List<Culture>>>
    {
        private readonly IBaseRepository<Culture> cuRep;
        private readonly IMapper mapper;

        public QueryCultureHandler(IBaseRepository<Culture> cuRep,IMapper mapper)
        {
            this.cuRep = cuRep;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<Culture>>> Handle(QueryCultureCommand request, CancellationToken cancellationToken)
        {
           ApiResult<List<Culture>> result = new ApiResult<List<Culture>>();
            var list = cuRep.GetAll().Where(x => x.ProductId == request.ProductId);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
